package com.ruoyi.web.controller.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.dto.BdmShippingCostDto;
import com.ruoyi.system.domain.dto.BdmShoppingCostDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BdmShippingCost;
import com.ruoyi.system.service.IBdmShippingCostService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运费Controller
 * 
 * @author ruoyi
 * @date 2025-09-03
 */
@RestController
@RequestMapping("/admin/cost")
public class BdmShippingCostController extends BaseController
{
    @Autowired
    private IBdmShippingCostService bdmShippingCostService;

    /**
     * 查询运费列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BdmShippingCostDto bdmShippingCost)
    {
        startPage();
        List<BdmShippingCost> list = bdmShippingCostService.selectBdmShippingCostListDto(bdmShippingCost);
        return getDataTable(list);
    }

    /**
     * 查询运费列表
     */
    @GetMapping("/getList")
    public TableDataInfo list1(BdmShippingCost bdmShippingCost)
    {
        startPage();
        List<BdmShippingCost> list = bdmShippingCostService.selectBdmShippingCostList(bdmShippingCost);
        return getDataTable(list);
    }

    /**
     * 导出运费列表
     */
    @Log(title = "运费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BdmShippingCost bdmShippingCost)
    {
        List<BdmShippingCost> list = bdmShippingCostService.selectBdmShippingCostList(bdmShippingCost);
        ExcelUtil<BdmShippingCost> util = new ExcelUtil<BdmShippingCost>(BdmShippingCost.class);
        util.exportExcel(response, list, "运费数据");
    }

    /**
     * 获取运费详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bdmShippingCostService.selectBdmShippingCostById(id));
    }

    /**
     * 新增运费
     */
    @Log(title = "运费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BdmShippingCost bdmShippingCost)
    {
        return toAjax(bdmShippingCostService.insertBdmShippingCost(bdmShippingCost));
    }

    @PostMapping("save")
    public AjaxResult saveCost(@RequestBody BdmShoppingCostDto bdmShoppingCostDto) {
        return bdmShippingCostService.saveCost(bdmShoppingCostDto);
    }

    /**
     * 修改运费
     */
    @Log(title = "运费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BdmShippingCost bdmShippingCost)
    {
        return toAjax(bdmShippingCostService.updateBdmShippingCost(bdmShippingCost));
    }

    /**
     * 删除运费
     */
    @Log(title = "运费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bdmShippingCostService.deleteBdmShippingCostByIds(ids));
    }
}
